import {Actor, Action} from 'iflux2';
import {DetailType} from '../constant/action-type';

export default class DetailActor extends Actor {
    defaultState() {
        return {
            detail: {},
            logs: [],
            logistics: {},
            autoCancelTime: 0,
            autoConfirmTime: 0,
            afterSaleTime: 0,
            receiptList: [],
            activityRecordInfo: {},
            userLogo: ''
        }
    }


    @Action(DetailType.SET_DETAIL)
    setDetail(state, detail) {
        return state.set('detail', detail);
    }


    @Action(DetailType.SET_USER_LOGOS)
    setUserLogo(state, userLogo) {
        return state.set('userLogo', userLogo);
    }

    @Action(DetailType.SET_REMARK)
    setRemark(state, remark) {
        return state.setIn(['detail', 'sellerMark'], remark);
    }


    @Action(DetailType.SET_LOGS)
    setLogs(state, logs) {
        return state.set('logs', logs);
    }


    @Action(DetailType.SET_TIME)
    setCancelTime(state, {autoCancelTime, autoConfirmTime, afterSaleTime}) {
        return state.set('autoCancelTime', autoCancelTime).set('autoConfirmTime', autoConfirmTime).set('afterSaleTime', afterSaleTime);
    }


    @Action(DetailType.SET_LOGISTICS)
    setLogistics(state, logistics) {
        return state.set('logistics', logistics);
    }


    @Action(DetailType.SET_RECEIPTS)
    setReceipts(state, list) {
        return state.set('receiptList', list);
    }

    @Action(DetailType.ADD_RECEIPT)
    addReceipt(state, receipt) {
        return state.update('receiptList', (receiptList)=>receiptList.concat([receipt]));
    }


    @Action(DetailType.SET_ACTIVITYRECORDINFO)
    setActivityRecordInfo(state, activityRecordInfo) {
        return state.set('activityRecordInfo', activityRecordInfo);
    }
}